from django.db import models
from django.db.models.base import Model
from user.models import User
from device.models import Device
from django.core.validators import int_list_validator
from django.core.validators import validate_comma_separated_integer_list


class State(models.IntegerChoices):
    UNRESOLVED = 1, "未解决"
    UNCONFIRMED = 2, "待确认"
    RESOLVED = 3, "完成"


class Bug(models.Model):
    bugId = models.AutoField(primary_key=True, verbose_name="id")
    handleUser = models.CharField(max_length=20, validators=[
        validate_comma_separated_integer_list], verbose_name='处理用户', db_column="receiverUser")
    createUser = models.ForeignKey(
        User, on_delete=models.CASCADE, related_name='+', verbose_name='创建用户', db_column='sendUser')
    device = models.ForeignKey(Device, on_delete=models.CASCADE,
                               related_name='+', verbose_name='bug设备', db_column='device', blank=True)
    bugDescribe = models.TextField(verbose_name='bug描述', blank=True)
    loggerContnet = models.JSONField(verbose_name='日志内容', blank=True)
    createTime = models.DateTimeField(auto_now=True, verbose_name='创建时间')
    state = models.SmallIntegerField(
        choices=State.choices, default=State.UNRESOLVED, verbose_name='bug状态')


class Anchor(models.Model):
    device = models.ForeignKey(Device, on_delete=models.CASCADE,
                               related_name='+', verbose_name='设备', db_column='device', blank=True)
    createUser = models.ForeignKey(
        User, on_delete=models.CASCADE, verbose_name='创建用户')
    loggerContnet = models.JSONField(verbose_name='日志内容')
    createTime = models.DateTimeField(auto_now=True, verbose_name='创建时间')
